/**
 * 
 */
package com.wbcs.jbsf.auth.abs.impl;

import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

import com.wbcs.jbsf.auth.abs.AbstandLogin;
import com.wbcs.jbsf.dao.IDataModal;
import com.wbcs.jbsf.util.Consts;

/**
 * http和ajax登录实现
 * @author hawkfly
 */
public class CommonLogin extends AbstandLogin
{

    public CommonLogin(ServletRequest rq,ServletResponse rp)
    {
        super(rq,rp);
        // TODO Auto-generated constructor stub
    }

    /* (non-Javadoc)
     * @see com.wbcs.jbsf.auth.abs.AbstandLogin#checklogin()
     */
    @Override
	public String checklogin() throws SQLException
    {
        String username = request.getParameter(Consts.REQUEST_USERNAME);
        String password = request.getParameter(Consts.REQUEST_PASSWORD);
        String loginsql = Consts.SQL_LOGIN;
        
        String isLogin = jdaoTemplate.select(loginsql,new IDataModal<String>(){
            public String loadDatas(ResultSet rs,int ccount,ResultSetMetaData rmd,String dataModal) throws SQLException
            {
                dataModal = "用户名或密码错误！";
                String usercode = null;
                String userid = null;
                while(rs.next()){
                    dataModal = CONTINUE;
                    userid = rs.getString("userid");
                    usercode = rs.getString("usercode");
                }
                if(usercode == null)return dataModal;
                request.getSession().setAttribute(Consts.SESSION_USERCODE,usercode);
                request.getSession().setAttribute(Consts.SESSION_USERID,userid);
                return dataModal;
            }},username, password);
        return isLogin;
    }

}

